package client.comm.baoding.ui

import android.content.Intent
import androidx.lifecycle.Observer
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.api.bean.BankBind
import client.comm.baoding.api.event.EventBank
import client.comm.baoding.api.event.EventUserInfo
import client.comm.baoding.databinding.ActivitySetbank3CodeBinding
import client.comm.baoding.ui.vm.SetBank3ViewModel
import client.comm.commlib.toast.toast
import org.greenrobot.eventbus.EventBus

/**
 * 绑定银行卡验证
 */
class Bank3CodeActivity :
    BaseMiddleActivity<SetBank3ViewModel, ActivitySetbank3CodeBinding>() {

    var bank_bind: BankBind? = null
    var status: String? = null

    override fun getLayout(): Int {
        return R.layout.activity_setbank3_code
    }

    override fun initViewModel(): SetBank3ViewModel = createViewModel()

    override fun initView() {
        binding.event = this
        binding.vm = viewModel

        bank_bind = intent.getParcelableExtra<BankBind>("bank_bind")
        status = intent.getStringExtra("status")
    }

    override fun observerUI() {
//        viewModel.callBindCode.observe(this, Observer {
//            it?.apply {
//                if (isSuccess) {
//                    toast("操作成功")
//                    finish()
//                }
//            }
//        })
        viewModel.codeRet.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("操作成功")
                    // (绑卡的短信确认传1   充值的短信确认传2  提现的短信传3)
                    if (status.equals("1")) {
                        EventBus.getDefault().post(EventBank())
                    } else if (status.equals("3")) {
                        EventBus.getDefault().post(EventUserInfo())
                        startActivity(Intent(this@Bank3CodeActivity, KtOrderActivity::class.java))
                    }
                    finish()
                }
            }
        })
    }


    fun ok() {
        bank_bind?.let {
            viewModel.verifyPhone(it, status!!)
        }
//        bank_bind?.let {
//            viewModel.confirmPay(it)
//        }
    }


}